function res = resid_dim5case2_pscc(x,la,u,mu0,phi,kap0,eta0,be,del,d,Pzz,cz,T_guess,M)
%function solving for equilibrium (given lambda) in case where all firms actively sell in top productivity 
%state and no firm actively sells in other states

options = optimoptions('fsolve','TolFun',1e-9,'TolX',1e-9,'StepTolerance',1e-9,'Display','none');

shat_1=x(1);dim=5;

%solve for theta corresponding to shat
th_res = @(th) la-mu_pscc(th,mu0,eta0)*eta_el_pscc(th,mu0,eta0)/(1-eta_el_pscc(th,mu0,eta0))*shat_1*kap_s_pscc(shat_1,kap0,phi)/(1+eta_pscc(th,mu0,eta0)*shat_1);
[th_1,fval,exit_flag1] = fsolve(th_res,T_guess(1),options);
if min(exit_flag1)<1,disp('issue: case 2');end

%match surplus given active selling behavior
S_1=kap_s_pscc(shat_1,kap0,phi)/eta_pscc(th_1,mu0,eta0)+la/mu_pscc(th_1,mu0,eta0);

%match surpluses given behavior in active selling state and otherwise
S_vec=M*(u*ones(dim,1)-cz+be*(1-del)*(1-d)*(-la*ones(dim,1)-Pzz(:,1)*kap_n_pscc(shat_1,kap0,phi)));

%equilibrium consistency condition for surplus
res=S_vec(1)-S_1;
end